#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;

#define PI 3.141592653
#define IMGSIZE 512
#define NRAY 768
#define NANG 180
#define RAY_S 128
#define RAY_E 639

void get_voxel(int np, int nr, int *voxels, float *weights, int &num)
{
    float ang= static_cast<float>(np / 180.f) * PI;
    float center_x=IMGSIZE/2-1;
    float center_y=-(IMGSIZE/2-1);

    //np==0
    if (np==0){
        num = IMGSIZE;
        for (int i=0; i<NRAY; ++i){
            voxels[i] = nr-RAY_S+i;
            weights[i] = 1.0f;
        }
        return;
    }
    //np==90
    if (np==90){
        num = IMGSIZE;
        for (int i=0; i<NRAY; ++i){
            voxels[i]=RAY_S + (IMGSIZE-1) - nr + i*IMGSIZE;
            weights[i]=1.0f;
        }
        return;
    }

    //直线方程为
    //cos(angle)*y + sin(ang)*x - (cos(ang)*center_y + sin(ang)*center_y + nr - NRAY/2 - 0.5)
    //x轴的截距乘以sin，或者y轴的截距乘以cos
    float input = 0.f;
    input = cos(ang)*center_y + sin(ang)*center_x + nr - NRAY/2 - 0.5f; //令y==0，与x轴的交点和sin的乘积

    //首先考虑[0,90)
    if (np <90) {
        num = 0;
        int top = 0;
        int left = 0;
        float down_input;
        int type = (input < 0.f) ? 0 : 1;
        if (type)
            left = int(input / sin(ang));
        else
            top = int(input / cos(ang));

        while (top > -IMGSIZE && left < IMGSIZE-1) {
            switch (type) {
                //从左边界射入的射线
                case 0:
                    voxels[num] = (-top) * IMGSIZE + left;
                    down_input = input - (top - 1) * cos(ang); //令y==y+1，该直线的x值与sin的乘积
                    if (down_input < (left + 1) * sin(ang)) {//从下边界射出
                        weights[num] = (down_input / sin(ang) - left) / cos(ang);
                        num++;
                        top--;
                        type = 1;
                    } else {//从右边界射出
                        weights[num] = 1 / cos(ang);
                        num++;
                        left++;
                        type = 0;
                    }
                    break;
                    //从上边界射入的射线
                case 1:
                    voxels[num] = (-top) * IMGSIZE + left;
                    down_input = input - (top - 1) * cos(ang); //令y==y+1，该直线的x值与sin的乘积
                    if (down_input < (left + 1) * sin(ang)) {//从下边界射出
                        weights[num] = 1 / sin(ang);
                        num++;
                        top--;
                        type = 1;
                    } else {//从右边界射出
                        weights[num] = (1 - (down_input - (1 + left) * sin(ang)) / cos(ang)) / sin(ang);
                        num++;
                        left++;
                        type = 0;
                    }
                    break;
                default:
                    cout << "Exception" << endl;
                    exit(1);
            }
        }
    }
    //考虑[91-180)角度
    else{
        num = 0;
        int top = 0;
        int right = IMGSIZE;
        float down_input;
        int type = (input > IMGSIZE) ? 0 : 1;
        if (type)
            right = int(input / sin(ang));
        else
            top = int(input / cos(ang));

        while (top>-IMGSIZE && right>1) {
            switch(type){
                //从右边射入
                case 0:
                    voxels[num] = (-top) * IMGSIZE + right-1;
                    down_input = input - (top - 1) * cos(ang); //令y==y+1，该直线的x值与sin的乘积
                    if (down_input > (right - 1) * sin(ang)) {//从下边界射出
                        weights[num] = (right - down_input / sin(ang)) / cos(PI-ang);
                        num++;
                        top--;
                        type = 1;
                    } else {//从左边界射出
                        weights[num] = 1 / cos(PI-ang);
                        num++;
                        right--;
                        type = 0;
                    }
                    break;
                //从上边界射入的射线
                case 1:
                    voxels[num] = (-top) * IMGSIZE + right-1;
                    down_input = input - (top - 1) * cos(ang); //令y==y+1，该直线的x值与sin的乘积
                    if (down_input > (right - 1) * sin(ang)) {//从下边界射出
                        weights[num] = 1 / sin(PI-ang);
                        num++;
                        top--;
                        type = 1;
                    } else {//从左边界射出
                        weights[num] = 1/sin(PI-ang) - (right-1-down_input/sin(ang))/cos(PI-ang);
                        num++;
                        right--;
                        type = 0;
                    }
                    break;
                default:
                    cout << "Exception" << endl;
                    exit(1);
            }
        }
    }
    return;
}

int main()
{
    int np;
    int nr;
    cin>>np>>nr;
    int num=0;
    int voxels[1024];
    float weights[1024];
    memset(voxels, 0, sizeof(int)*1024);
    memset(weights, 0.f, sizeof(float)*1024);
    get_voxel(np, nr, voxels, weights, num);

    return 0;
}
